﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Scripting.GarbageCollector
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using System.Runtime.CompilerServices;
using UnityEngine.Bindings;

#nullable disable
namespace UnityEngine.Scripting
{
  /// <summary>
  ///   <para>API to control the garbage collector on the Mono and IL2CPP scripting backends.</para>
  /// </summary>
  [NativeHeader("Runtime/Scripting/GarbageCollector.h")]
  public static class GarbageCollector
  {
    public static event Action<GarbageCollector.Mode> GCModeChanged;

    /// <summary>
    ///   <para>Set and get global garbage collector operation mode.</para>
    /// </summary>
    public static GarbageCollector.Mode GCMode
    {
      get => GarbageCollector.GetMode();
      set
      {
        if (value == GarbageCollector.GetMode())
          return;
        GarbageCollector.SetMode(value);
        if (GarbageCollector.GCModeChanged == null)
          return;
        GarbageCollector.GCModeChanged(value);
      }
    }

    [NativeThrows]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void SetMode(GarbageCollector.Mode mode);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern GarbageCollector.Mode GetMode();

    /// <summary>
    ///   <para>Reports whether incremental garbage collection is enabled.</para>
    /// </summary>
    public static extern bool isIncremental { [NativeMethod("GetIncrementalEnabled"), MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///   <para>The target duration of a collection step when performing incremental garbage collection.</para>
    /// </summary>
    public static extern ulong incrementalTimeSliceNanoseconds { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>Perform incremental garbage collection for the duration specified by the nanoseconds parameter.</para>
    /// </summary>
    /// <param name="nanoseconds">The maximum number of nanoseconds to spend in garbage collection.</param>
    /// <returns>
    ///   <para>Returns true if additional garbage collection work remains when the method returns and false if garbage collection is complete. Also returns false if incremental garbage collection is not enabled or is not supported on the current platform.</para>
    /// </returns>
    [NativeMethod("CollectIncrementalWrapper")]
    [NativeThrows]
    [MethodImpl(MethodImplOptions.InternalCall)]
    public static extern bool CollectIncremental(ulong nanoseconds = 0);

    /// <summary>
    ///   <para>Garbage collector operation mode.</para>
    /// </summary>
    public enum Mode
    {
      /// <summary>
      ///   <para>Disable garbage collector.</para>
      /// </summary>
      Disabled,
      /// <summary>
      ///   <para>Enable garbage collector.</para>
      /// </summary>
      Enabled,
      /// <summary>
      ///   <para>Disable automatic invokations of the garbage collector, but allow manually invokations.</para>
      /// </summary>
      Manual,
    }
  }
}
